﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.OperationVMs
{
    public partial class OperationListVM : BasePagedListVM<Operation_View, OperationSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Operation_View>> InitGridHeader()
        {
            return new List<GridColumn<Operation_View>>{
                
                this.MakeGridHeader(x => x.Operation_LineCode).SetTitle(@Localizer["Page.产线信息"].Value),
                this.MakeGridHeader(x => x.Operation_OperationId).SetTitle(@Localizer["Page.工序编码"].Value),
                this.MakeGridHeader(x => x.Operation_OperationName).SetTitle(@Localizer["Page.工序名称"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Operation_View> GetSearchQuery()
        {
            var query = DC.Set<Operation>()
                
                .CheckEqual(Searcher.LineCodeId, x=>x.LineCodeId)
                .CheckContain(Searcher.OperationId, x=>x.OperationId)
                .CheckContain(Searcher.OperationName, x=>x.OperationName)
                .Select(x => new Operation_View
                {
				    ID = x.ID,
                    
                    Operation_LineCode = DC.Set<Line>().Where(z0 => z0.LineCode == x.LineCodeId).Select(y => y.LineCode).FirstOrDefault(),
                    Operation_OperationId = x.OperationId,
                    Operation_OperationName = x.OperationName,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Operation_View: Operation
    {
        
        public string Operation_LineCode { get; set; }
        public string Operation_OperationId { get; set; }
        public string Operation_OperationName { get; set; }

    }

}